package com.xk.sms.mq;

import com.hy.common.utils.JsonUtils;
import com.xk.sms.config.SmsProperties;
import com.xk.sms.utils.SmsUtils;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.Map;

@EnableConfigurationProperties(SmsProperties.class)
@Component
public class SmsListener {
    @Autowired
    private SmsUtils smsUtils;

    @Autowired
    private SmsProperties prop;
    /**
     * 短信验证码的发送
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "sms.verify.code.queue", durable = "true"),
            exchange = @Exchange(name = "xk.sms.exchange",type = ExchangeTypes.TOPIC),
            key = {"sms.verify.code"}))
    public void ListenerInsertOrUpdate(Map<String,String> msg) throws Exception {
        //处理消息
        smsUtils.sendSms(msg.remove("phone"),prop.getSignName(),prop.getVerifyCodeTemplate(),JsonUtils.toString(msg));

}
}
